package com.laosg.study.base.ch1

import scala.collection.immutable.Range
import util.control.Breaks._
/**
  * Created by kaimin on 4/5/2019.
  * time : 08:47
  */
object ConditionDemo {

  def main(args: Array[String]): Unit = {
    var age: Int = 20
    if (age > 10) {
      printf("年龄是大于10的，年龄是:%d", age)
    } else {
      printf("年龄是小于10的，年龄是:%d", age)
    }
    val res = if (age > 100) 100 else 20
    println("scala中的三木运算可以这种：" + res)
    var num=10
    println("前后闭合")
    for (i <- 1 to 10 ) {

      println(num+i)
    }
    println("前后闭合 并且控制步长")
    for (i <- Range(1,10,2) ) {

      println(num+i)
    }
    println("相当于到3-1")
    for (i <- 1 until  3) {

      println(num+i)
    }
    //循环守卫，相当于 continue
    println("循环守卫，相当于 continue")
    for (i<-1 until 10 if i!=2) {
      println(num+i)
    }

    println("循环加入变量")
    for (i<-1 until 10 ;j=i-1) {
      println(j)
      println("------")
      println(num+i)
    }
    println("嵌套循环 括号改写")
    for {i<- 1 to 3
         j<- 1 to i} {
      println("i="+i+" j="+j)
    }
    println("嵌套循环 ")
    var list = List("aa",1);
    for (item<- list) {
      println(item)
    }
    println("对for循环对内容赋值给变量")
    var res1=for (i<- 1 to 3) yield i
    println(res1)
    var step=10
    while (step<20) {
      println("while xunhuan")
      step+=1
    }
    println("------")
    do {
      println("while do")
      step+=1
    }while(step<25)



    var total=0
    breakable{
      while (true) {


        total+=1
        println(total)
        if (total==3){
          break()
        }
      }
    }
    println("ok")
  }

}
